package com.hlmc.controller;

import com.hlmc.entity.*;
import com.hlmc.service.FlService;
import com.hlmc.service.Query_360_Service;
import com.hlmc.service.YunService;
import com.hlmc.service.Zy2Service;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class YunBo_Controller {

    @Resource
    private Query_360_Service query_360;

    @Resource
    private FlService fl_service;

    @Resource
    private YunService query_yun;

    @Resource
    private Zy2Service zy2Service;

    @ResponseBody
    @RequestMapping("/v_yun")
    public List<Yun_Video> videoPage(Yun_Video ds, @RequestParam(defaultValue = "1") int page){

        Map<String,Object> map=new HashMap<String, Object>();
        int pageSize=12;
        int totalRecord=query_yun.findTotalNum();
        Page<Yun_Video> coverPage = new Page<Yun_Video>(pageSize, page, totalRecord, null);
        int start = (coverPage.getCurrentPage() - 1) * pageSize;
        map.put("start", start);
        map.put("size", pageSize);
        List<Yun_Video> cover=new ArrayList<Yun_Video>();
        cover=query_yun.findCoverpage(map);
        return cover;
    }

    @RequestMapping("/v_yun2")
    public String videoPage2(Yun_Video ds, @RequestParam(defaultValue = "1") int page, Model model){

        Map<String,Object> map=new HashMap<String, Object>();
        int pageSize=24;
        int totalRecord=query_yun.findTotalNum();
        Page<Yun_Video> coverPage = new Page<Yun_Video>(pageSize, page, totalRecord, null);
        int start = (coverPage.getCurrentPage() - 1) * pageSize;
        map.put("start", start);
        map.put("size", pageSize);
        List<Yun_Video> cover=new ArrayList<Yun_Video>();
        cover=query_yun.findCoverpage(map);
        model.addAttribute("listCover",cover);

        List<Banner> banners=new ArrayList<Banner>();
        banners=query_360.findBner();
        model.addAttribute("banners",banners);
        model.addAttribute("baseUrl","fl");
        model.addAttribute("pageUrl","v_yun2.do?"+"&page=");
        model.addAttribute("totalRecord",totalRecord);
        model.addAttribute("curr",page);
        return "index";
    }

    @ResponseBody
    @RequestMapping("/v_image")
    public Yun_Video findVideoByTitle(String img){

      Yun_Video dt=new Yun_Video();
      dt=query_yun.findVideoImage(img);
        return dt;
    }

    @RequestMapping("/v_image2")
    public Yun_Video findVideoByTitle2(String img){

        Yun_Video dt=new Yun_Video();
        dt=query_yun.findVideoImage(img);
        return dt;
    }

}
